package com.dcy.daily.skill.rabbitMQ.official.helloWord;

import com.dcy.daily.skill.rabbitMQ.official.utils.MQConnectUtil;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

/**
 *
 * Hello word
 * 生成者
 * RabbitMQ 的学习例子（https://www.rabbitmq.com/tutorials/tutorial-one-java.html）。
 *  @author duanchunyu
 * @version 1.0.0
 * @createTime 2021年07月15日 15:40
 */
public class Send {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String message = "Hello World!";
        try (Connection connection = MQConnectUtil.getConnection()) {
            Channel channel = connection.createChannel();
            //声明Queue
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            //发送消息
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());

            System.out.println(" [x] Sent '" + message + "'");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
